package eerbaar.v2.pattern.server.internal;

import java.util.ArrayList;
import java.util.List;

import eerbaar.shared.tree.INode;
import eerbaar.v2.pattern.server.IProgramGenerator;
import eerbaar.v2.pattern.server.IProgramListener;

abstract class AbstractGenerator implements IProgramGenerator {

    private final List<IProgramListener> listeners = new ArrayList<IProgramListener>();

    @Override
    public void addProgramListener(IProgramListener listener) {
        this.listeners.add(listener);
    }

    protected void fireProgramFound(INode idea) {
        for (IProgramListener listener : this.listeners) {
            listener.foundProgram(idea);
        }
    }

    @Override
    public void removeProgramListener(IProgramListener listener) {
        this.listeners.remove(listener);
    }

}
